﻿@using eLoan.Models;
@model LoanListModel

@{
    ViewBag.Title = "Loans";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Loans</h2>
        <ol class="breadcrumb">
            <li>
                Funding
            </li>
            <li class="active">
                <strong>Loans</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            @using (Html.BeginForm("RefreshLoanList", "Funding", FormMethod.Post, new { id = "saveForm" }))
            {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div>
                        <a href="@Url.Action("AddEdit", "Loan")" class="btn btn-primary">Create a new loan</a>
                    </div>
                    <div class="divSearch">
                        <table class="table-search">
                            <tr>
                                <td>
                                    <span>@Html.LabelFor(m => m.Branches)</span>
                                    @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "text-box single-line" })
                                </td>
                                <td>
                                    <span>@Html.LabelFor(m => m.SearchText)</span>
                                    @Html.TextBoxFor(m => m.SearchText, new { @id = "txtSearchText", @class = "text-box single-line", @width = "50%" })
                                </td>
                                <td>
                                    <button type="submit" id="btnSearch" class="btn btn-primary btnSearch" name="command" value="Refresh">Search</button>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="divScroll">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>Document No</th>
                                    <th>Agent</th>
                                    <th>Borrower</th>
                                    <th>Loan Amount</th>
                                    <th>Receivable</th>
                                    <th>Total Payment</th>
                                    <th>Proceed Type</th>
                                    <th>Loan Status</th>
                                    <th>Is Active</th>
                                    <th colspan="3"></th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.LoanList.Count(); i++)
                                { 
                                <tr>
                                    <td>@Html.ActionLink(Model.LoanList[i].LoanItem.DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.LoanList[i].LoanItem.DocumentNo }, null)</td>
                                    <td>@Html.DisplayFor(m => Model.LoanList[i].LoanItem.AgentName)</td>
                                    <td>@Html.DisplayFor(m => Model.LoanList[i].LoanItem.BorrowerName)</td>
                                    <td style="text-align:right">@Html.ValueFor(m => Model.LoanList[i].LoanItem.LoanAmount, "{0:#,###,##0.00}")</td>
                                    <td style="text-align:right">@Html.ValueFor(m => Model.LoanList[i].LoanItem.Receivable, "{0:#,###,##0.00}")</td>
                                    <td style="text-align:right">@Html.ValueFor(m => Model.LoanList[i].LoanItem.TotalPayment, "{0:#,###,##0.00}")</td>
                                    <td>@Html.ActionLink(Model.LoanList[i].LoanItem.ProceedTypeName, "PaymentHistory", "Loan", null, null, null, new { documentNo = Model.LoanList[i].LoanItem.DocumentNo }, null)</td>
                                    <td>@Html.DisplayFor(m => Model.LoanList[i].LoanItem.LoanStatus)</td>
                                    <td style="text-align:center">@Html.DisplayFor(m => Model.LoanList[i].LoanItem.IsActive)</td>
                                    <td>@Html.ActionLink("Co-Makers And Collaterals", "LoanCoMakersAndCollaterals", "Loan", null, null, null, new { documentNo = Model.LoanList[i].LoanItem.DocumentNo, borrowerID = Model.LoanList[i].LoanItem.BorrowerID, branchCode = Model.LoanList[i].LoanItem.BranchCode }, null)</td>
                                    <td>@Html.ActionLink("Journal", "LoanJournal", "Loan", null, null, null, new { documentNo = Model.LoanList[i].LoanItem.DocumentNo }, null)</td>
                                    <td>@Html.ActionLink("Edit", "AddEdit", "Loan", null, null, null, new { documentNo = Model.LoanList[i].LoanItem.DocumentNo, branchCode = Model.SelectedBranchCode }, new { @style = Model.LoanList[i].EditLoanStyle })</td>
                                </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
            }
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    
    <style>
        .divScroll {
            height: 400px;
            overflow-y: scroll;
            border: solid 1px #EBEBEB;
        }

        .divSearch {
            background-color: #F5F5F6;
            border: 1px solid #EBEBEB;
            margin-top:5px;
        }

        .table-search {
            width: 50%;
            border: none;
        }

        .table-search td {
            margin: 10px 10px 10px 10px;
            padding: 10px 10px 10px 10px;
            vertical-align: bottom;
        }

        .table-search td .btnSearch {
            margin-bottom: 0px;
        }

        .table-search td span {
            margin-left: 5px;
        }

        
    </style>

}


@section Scripts {

    <script type="text/javascript">

        $(window).keydown(function (event) {
            if (event.keyCode == 13) {
                Refresh();
                return false;
            }
        });

        function Refresh() {
            document.getElementById('btnSearch').click();
        }

    </script>

}
